
package com.example.cia.database.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.cia.database.mysql.dao.impl.addDeviceImpl;

public class addDeviceServlet extends HttpServlet{

	/**
	 * 添加设备servlet
	 */
	private static final long serialVersionUID = 2793149861637727858L;

	public void doGet(HttpServletRequest request,HttpServletResponse response)
			throws ServletException,IOException{

		//获取添加设备时的初始化信息
		String id = request.getParameter("id");
		String description = request.getParameter("description");
		int state = Integer.parseInt(request.getParameter("state"));

		//获取服务对象
		addDeviceImpl adi = new addDeviceImpl();
				
		//执行添加方法
		try {
			int result = adi.add(id, description, state);
			//返回信息，执行成功返回true，失败返回false
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			out.print((result!=0));
			out.flush();
			out.close();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
				
		
	}
	
	public void doPost(HttpServletRequest request,HttpServletResponse response)
			throws ServletException,IOException{
		
	}

}
